//
//  ZJHallController.m
//  Lottery
//
//  Created by ZJ on 2018/8/14.
//  Copyright © 2018年 iCatch Technology Inc. All rights reserved.
//

#import "ZJHallController.h"

@interface ZJHallController ()

@property (nonatomic, weak) UIView *coverView;
@property (nonatomic, weak) UIImageView *imageView;

@end

@implementation ZJHallController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    UIImage *image = [UIImage imageNamed:@"CS50_activity_image"];
    
    // 告诉系统 使用这个图片的时候 不进行渲染
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    // 创建item
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(activityClick)];
    
    self.navigationItem.leftBarButtonItem = item;
    
    // bar 背景颜色
//    [self.navigationController.navigationBar setBackgroundColor:[UIColor redColor]];
    
    // 创建item
    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"嘿嘿" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.rightBarButtonItem = item1;
    
    // 主题的颜色(bar 上 item 文字变色)
//    [self.navigationController.navigationBar setTintColor:[UIColor redColor]];
    
    // 设置64的颜色(bar 的颜色)
//    [self.navigationController.navigationBar setBarTintColor:[UIColor redColor]];
    
    // 设置不透明
//    [self.navigationController.navigationBar setTranslucent:NO];
}

// 活动的点击事件
- (void)activityClick {
    // 遮罩
    UIView *coverView = [[UIView alloc] initWithFrame:kScreenSize];
    coverView.backgroundColor = [UIColor blackColor];
    coverView.alpha = 0.5;
    
    // 添加到最外层的控制器
    [self.tabBarController.view addSubview:coverView];
    self.coverView = coverView;
    
    // imageView
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"showActivity"]];
    
    // 开启用户交互
    imageView.userInteractionEnabled = YES;
    imageView.center = self.view.center;
    
    //    [coverView addSubview:imageView];
    // 注意: 不添加到 cover 上的原因 是因为 父控件如果透明 那么子控件也会透明
    [self.tabBarController.view addSubview:imageView];
    self.imageView = imageView;
    
    // 关闭按钮
    UIButton *closeButton = [[UIButton alloc] init];
    // 获取图片
    UIImage *closeButtonImage = [UIImage imageNamed:@"alphaClose"];
    closeButton.frame = CGRectMake(CGRectGetWidth(imageView.frame) - closeButtonImage.size.width, 0, 0, 0);
    [closeButton setBackgroundImage:closeButtonImage forState:UIControlStateNormal];
    [closeButton sizeToFit];
    [imageView addSubview:closeButton];
    
    // 监听关闭按钮的点击
    [closeButton addTarget:self action:@selector(closeClick) forControlEvents:UIControlEventTouchUpInside];
}

// 关闭按钮
- (void)closeClick {
    [UIView animateWithDuration:0.25 animations:^{
        [self.coverView removeFromSuperview];
        [self.imageView removeFromSuperview];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
